package com.info.zhiduoduo.common.excelconverter;

import com.alibaba.excel.converters.Converter;
import com.alibaba.excel.enums.CellDataTypeEnum;
import com.alibaba.excel.metadata.CellData;
import com.alibaba.excel.metadata.property.ExcelContentProperty;

/**
 * 账目流水类型转换
 */
public class FlowtypeConverter implements Converter<Integer> {

	@Override
	public Class supportJavaTypeKey() {
		return null;
	}

	@Override
	public CellDataTypeEnum supportExcelTypeKey() {
		return null;
	}

	@Override
	public Integer convertToJavaData(CellData cellData, ExcelContentProperty excelContentProperty,
	                                 com.alibaba.excel.metadata.GlobalConfiguration globalConfiguration) throws Exception {
		String value = cellData.getStringValue();
		if ("收入".equals(value)) {
			return 1;
		} else {
			return 2;
		}
	}

	@Override
	public CellData convertToExcelData(Integer integer, ExcelContentProperty excelContentProperty,
	                                   com.alibaba.excel.metadata.GlobalConfiguration globalConfiguration) throws Exception {
		if (integer == null) {
			return new CellData("");
		} else if (integer == 1) {
			return new CellData("收入");
		} else {
			return new CellData("支出");
		}
	}
}
